package com.tax.config.response;

import com.alibaba.fastjson.JSON;
import lombok.Data;

import java.io.Serializable;

/**
 * 返回请求信息
 *@author 段德辉
 * @param <T>
 * @author windows
 */
@Data
public class Response<T> implements Serializable {

	/**
	 * 返回码
	 */
	private Integer status;
	/**
	 * 返回时间戳
	 */
	private Long time;
	/**
	 * 返回提示信息
	 */
	private String msg;

	/**
	 * 服务器版本号
	 */
	private static final String VERSION = "v1.0.0";

	/**
	 * 数据详情
	 */
	private  T data;
	private String extraMsg="";

	public Response() {
		super();
		this.status = ResponseCode.OK.getCode();
		this.msg = ResponseCode.OK.getMsg();
		this.time = System.currentTimeMillis() / 1000;
	}

	public Response(T data) {
		super();
		this.status = ResponseCode.OK.getCode();
		this.msg = ResponseCode.OK.getMsg();
		this.time = System.currentTimeMillis() / 1000;
		this.data = data;
	}

	public Response(Integer code, String msg, T data) {
		super();
		this.status = code;
		this.msg = msg;
		this.time = System.currentTimeMillis() / 1000;
		this.data = data;
	}

	public Response(Integer code, String msg) {
		super();
		this.status = code;
		this.msg = msg;
		this.time = System.currentTimeMillis() / 1000;
	}

	public Response(ResponseCode responseCode) {
		super();
		this.status = responseCode.getCode();
		this.time = System.currentTimeMillis() / 1000;
		this.msg = responseCode.getMsg();
	}


	public Response(ResponseCode responseCode, String extraMsg) {
		super();
		this.status = responseCode.getCode();
		this.time = System.currentTimeMillis() / 1000;
		this.msg = responseCode.getMsg();
		this.extraMsg=extraMsg;
	}

	public Response(ResponseCode responseCode, T data, String msg, String extraMsg) {
		super();
		this.status = responseCode.getCode();
		this.time = System.currentTimeMillis() / 1000;
		this.msg = msg;
		this.data=data;
		this.extraMsg=extraMsg;
	}

	public Response(ResponseCode responseCode, String msg, String extraMsg) {
		super();
		this.status = responseCode.getCode();
		this.time = System.currentTimeMillis() / 1000;
		this.msg = msg;
		this.extraMsg=extraMsg;
	}

	public boolean success() {
		return status.equals(ResponseCode.SUCCESS.getCode());
	}

	public String getExtraMsg() {
		return extraMsg;
	}

	public void setExtraMsg(String extraMsg) {
		this.extraMsg = extraMsg;
	}

	@Override
	public String toString() {
		return "Response [status=" + status + ", msg=" + msg + ",extraMsg=" + extraMsg + ", data=" + JSON.toJSONString(data) + "]";
	}

}
